/*   Valhalla MailChecker -- Simple IMAP Mail Checker
*    Copyright (C) 2010-2011  Guillaume Florimond (gflorimond at gmail dot com)
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package fr.valhalla.mailcheck;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 *
 * @author guillaume
 */
public class GlobalPreferences {
    Properties props = new Properties();

    // Préférences
    public boolean openMainWindowOnStart = false;
    public boolean showGUIWarnings = true;
    public boolean useMiniCheckPane = false;

    public GlobalPreferences() {
        // Ouverture du fichier contenant de properties
        try {
            FileInputStream in = new FileInputStream("fr.valhalla.mailcheck.preferences.properties");
            props.load(in);
            in.close();

            // Chargement des données dans les variables de classe
            openMainWindowOnStart = new Boolean(props.getProperty("openMainWindowOnStart"));
            showGUIWarnings = new Boolean(props.getProperty("showGUIWarnings"));
            useMiniCheckPane = new Boolean(props.getProperty("useMiniCheckPane"));
        }
        catch(FileNotFoundException e) {
            // Le fichier n'existe pas : on le crée
            try {
                props.store(new FileOutputStream(new File("fr.valhalla.mailcheck.preferences.properties")), null);
            }
            catch(Exception e2) { e2.printStackTrace(); }
        }
        catch(IOException e) { e.printStackTrace(); }
    }

    public void savePreferences() {
        props.setProperty("openMainWindowOnStart", new Boolean(openMainWindowOnStart).toString());
        props.setProperty("showGUIWarnings", new Boolean(showGUIWarnings).toString());
        props.setProperty("useMiniCheckPane", new Boolean(useMiniCheckPane).toString());

        try {
            props.store(new FileOutputStream("fr.valhalla.mailcheck.preferences.properties"),"Global Preferences");
        } catch(Exception e) { e.printStackTrace(); }
    }

}
